/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2022-08-17
 * Time: 17:02
 */

abstract class Shape {


    abstract public void draw();

    public void drawing() {
        System.out.println("画图中");
    }
    //抽象类不能有方法体
    // System.out.println("画图");


/*    abstract private void drawing() {
        //非法得修饰组合 abstract 和 private
    }*/

/*    //抽象方法不能被final和static修饰，因为抽象方法要被子类重写
    abstract public static void methodA(){
        //抽象方法不能用static修饰
    }

    abstract final void methodB(){
        //修饰符得非法组合  abstract 和 final
    }*/


}

class Triangle extends Shape {
    //抽象类必须被继承，并且继承以后要重写父类中得抽象方法
    @Override
    public void draw() {
        System.out.println("画一个三角形");
    }
}

abstract class Rectangle extends Shape {
    //如果不重写父类中得抽象方法，则子类必须用abstract修饰
    public Rectangle() {
        System.out.println("抽象类中可以有构造方法，供子类创建对象是初始化父类得成员变量");
    }
}

class Animal {
    public String name;

    public Animal(String name) {
        this.name = name;
    }

}

interface IFlying {
    void fly();
}

interface IRunning {
    void run();
}

interface ISwimming {
    void swim();
}

class Cat extends Animal implements IRunning {

    public Cat(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "用四条腿跑");
    }
}

class Fish extends Animal implements ISwimming,IRunning {

    public Fish(String name) {
        super(name);
    }

    @Override
    public void swim() {
        System.out.println(this.name + "用尾巴游泳");
    }

    @Override
    public int hashCode() {
        return super.hashCode();
    }

    @Override
    public void run() {

        System.out.println(name+"鱼跃");
    }
}

class Frog extends Animal implements IRunning, ISwimming {

    public Frog(String name) {
        super(name);
    }

    @Override
    public void run() {
        System.out.println(this.name + "用腿跳");
    }

    @Override
    public void swim() {
        System.out.println(this.name + "用腿游泳");
    }
}

//接口只需要关注是否具备某种能力，无需多关注类型
//例如 无论是不是会跑得东西，只需要实现了跑这个接口就可以具备这个能力

class Robot implements IRunning{

    private String name;
    public Robot(String name){
        super();
        this.name = name;
    }
    @Override
    public void run() {
        System.out.println(this.name+"用轮子跑");
    }
}

public class Test_0817 {

    public static void  wolk (IRunning running){
        System.out.println("我带着伙伴去散步");
        running.run();
    }

    public static void main(String[] args) {
        //Shape shape = new Shape() ;  //图形类是抽象类，无法实例化

        Cat cat = new Cat("mimi");
        wolk(cat);

        wolk(new Frog("青蛙"));
        wolk(new Fish("小鲤鱼"));

        wolk(new Robot("擎天柱"));
    }
}

